package com.ydd.controller.user;

import com.ydd.dto.ArticlePageDTO;
import com.ydd.dto.LoginAndRegDTO;
import com.ydd.entity.YddUser;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.UserIndexService;
import com.ydd.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author fang
 * @Date 2023-05-29 16:43
 */
@Api(tags = "用户端-基础数据")
@RestController
@RequestMapping("/api/index")
@Slf4j
public class UserIndexController {
    @Autowired
    UserIndexService userIndexService;

    @ApiOperation("文章列表数据")
    @GetMapping("/list")
    public Result<IndexArticleListVO> list(ArticlePageDTO articlePageDTO){
        log.info("文章列表数据");
        return Result.success(userIndexService.list(articlePageDTO));
    }

    @ApiOperation("首页和全局数据")
    @GetMapping("/index")
    public Result<IndexIndexVO> index(){
        log.info("首页和全局数据");
        return Result.success(userIndexService.index());
    }

    @ApiOperation("推荐文章")
    @GetMapping("/recommend")
    public Result<IndexArticleVO> recommend(){
        log.info("recommend");
        return Result.success(userIndexService.recommendOrHot("recommend"));
    }

    /**
     * 接口文档写的是最新文章，但是这里展示热门置顶文章数据
     * @return
     */
    @ApiOperation("热门置顶文章数据")
    @GetMapping("/hot")
    public Result<IndexArticleVO> hot(){
        log.info("热门置顶文章数据");
        return Result.success(userIndexService.recommendOrHot("hot"));
    }

    /**
     * 接口文档写的是热门置顶文章数据，但是这里展示最新文章
     * @param articlePageDTO
     * @return
     */
    @ApiOperation("热门置顶文章数据")
    @GetMapping("/new")
    public Result<IndexNewVO> newArticle(ArticlePageDTO articlePageDTO){
        log.info("热门置顶文章数据");
        return Result.success(userIndexService.newArticle(articlePageDTO));
    }

    @ApiOperation("文章详情数据")
    @GetMapping("/show")
    public Result<IndexShowVO> show(Long id){
        log.info("文章详情数据");
        return Result.success(userIndexService.show(id));
    }
    @ApiOperation("/用户注册接口")
    @PostMapping("/reg")
    public Result<YddUser> reg(@RequestBody LoginAndRegDTO loginAndRegDTO){
        log.info("用户注册接口：{}",loginAndRegDTO);
        YddUser yddUser = userIndexService.reg(loginAndRegDTO);
        return Result.success(yddUser);
    }


}
